import time
from functools import wraps

def fn_timer(function):
    @wraps(function)
    def function_timer(*args, **kwargs):
        t0 = time.time()
        result = function(*args, **kwargs)
        t1 = time.time()
        print("Total time running :" + str(t1 - t0)+"seconds" )
        return result

    return function_timer


def sort(n):
    for num in range(0,n):
        print(num)
    return 0
def sort2(n):
    if n:
        print(n)
        return sort2(n-1)
    return  0

# f(x) = a0+a1x+……
@fn_timer
def polynome(n,x,a):#T(n)=N^2
    for j in range(1,100000):
        p = a[0]
        for i in range(1,n+1):
            p += (a[i]*pow(x,i))
    return p


# f(x)=a0+x(a1+x(……))
@fn_timer
def polynome2(n,x,a):   #T(n)=N
    for j in range(1, 100000):
        p = a[n]
        for i in range(n,0,-1):
            p = (a[i-1]+x*p)
    return p

if __name__ == "__main__":
    a = [1,2,3,4,5,6,7,8,9,10]
    n = 9
    x = 1.1
    print(polynome(n,x,a))
    print(polynome2(n, x, a))

# 对比了两种多项式的计算方式，结果
# Total time running :0.3428027629852295seconds
# 100.00000000000006
# Total time running :0.15990686416625977seconds
# 100.00000000000006